/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.xs_price_apply_for.service;

import java.util.List;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.xs_book.entity.XsBook;
import com.jeeplus.modules.xs_book.mapper.XsBookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.xs_price_apply_for.entity.XsPriceApplyFor;
import com.jeeplus.modules.xs_price_apply_for.mapper.XsPriceApplyForMapper;

/**
 * 小说修改价格申请Service
 *
 * @author 天竹子
 * @version 2021-09-01
 */
@Service
@Transactional(readOnly = true)
public class XsPriceApplyForService extends CrudService<XsPriceApplyForMapper, XsPriceApplyFor> {

    @Autowired
    private XsBookMapper xsBookMapper;

    public XsPriceApplyFor get(String id) {
        return super.get(id);
    }

    public List<XsPriceApplyFor> findList(XsPriceApplyFor xsPriceApplyFor) {
        return super.findList(xsPriceApplyFor);
    }

    public Page<XsPriceApplyFor> findPage(Page<XsPriceApplyFor> page, XsPriceApplyFor xsPriceApplyFor) {
        return super.findPage(page, xsPriceApplyFor);
    }

    @Transactional(readOnly = false)
    public void save(XsPriceApplyFor xsPriceApplyFor) {
        if (StringUtils.isNotBlank(xsPriceApplyFor.getId())) {
            XsPriceApplyFor priceApplyFor = super.get(xsPriceApplyFor.getId());
            if ("2".equals(priceApplyFor.getIsPass()) && "1".equals(xsPriceApplyFor.getIsPass())) {
                XsBook xsBook = xsBookMapper.get(xsPriceApplyFor.getBook().getId());
                xsBook.setChapterPrice(xsPriceApplyFor.getPrice().toString());
                xsBookMapper.update(xsBook);
            }
        }
        super.save(xsPriceApplyFor);
    }

    @Transactional(readOnly = false)
    public void delete(XsPriceApplyFor xsPriceApplyFor) {
        super.delete(xsPriceApplyFor);
    }

}